/*
 *  Copyright (C) 2012 Компания ВИТ. web: http://diasled.ru Е-mail:  vit@diasled.ru
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package ru.apertum.diasled.redactor;

import java.util.LinkedList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Evgeniy Egorov
 */
public class SensorsTableModel extends AbstractTableModel {

    final private LinkedList<SensorDraw> sensors;

    public SensorsTableModel(LinkedList<SensorDraw> sensors) {
        this.sensors = sensors;
    }

    @Override
    public int getRowCount() {
        return sensors.size();
    }

    @Override
    public int getColumnCount() {
        //return 4;
        return 3;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return sensors.get(rowIndex).x;
            case 1:
                return sensors.get(rowIndex).y;
            case 2:
            //    return sensors.get(rowIndex).getPhisicalNum();
            //case 3:
                return sensors.get(rowIndex).getLogicalNum();
            default:
                throw new AssertionError();
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "X";
            case 1:
                return "Y";
            case 2:
            //    return "Ph";
            //case 3:
                return "Lo";
            default:
                throw new AssertionError();
        }
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
       // switch (columnIndex) {
       //     case 4:
       //         return Float.class;    
       //     default:
                return Integer.class;
       // }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return true;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                sensors.get(rowIndex).x  = (int) aValue;
                break;
            case 1:
                sensors.get(rowIndex).y = (int) aValue;
                break;
            case 2:
            //    sensors.get(rowIndex).setPhisicalNum((int) aValue);
            //    break;
            //case 3:
                sensors.get(rowIndex).setLogicalNum((int) aValue);
                break;
            default:
                throw new AssertionError();
        }
    }
    
    public void add(int index, SensorDraw sensor) {
        sensors.add(index, sensor);
    }

    public void remove(int index) {
        sensors.remove(index);
    }

    public void remove(SensorDraw sensor) {
        sensors.remove(sensor);
    }
}
